package com.qianbao.qianbaobusiness.ui.cashier;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.androidbase.utils.DisplayUtils;
import com.androidbase.utils.ToastUtils;
import com.baseandroid.config.Global;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.UserInfo;

public class SendEmailPopWindow extends PopupWindow {

    private View conentView;
    private View Uplayout;
    private TextView tv_send_email;

    private Context mContext;

    private onItmeclick mOnItmeclick;

    public SendEmailPopWindow(final Activity context, View view, final String startTime, final String endTime, final String type, onItmeclick onItmeclick) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.pop_send_email, null);
        tv_send_email = (TextView) conentView.findViewById(R.id.tv_send_email);
        Uplayout = view;
        mContext = context;
        mOnItmeclick = onItmeclick;
        tv_send_email.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //                Merchant m = Global.getUserInfoBean().getMerchant();
                UserInfo.User u = Global.getUserInfoBean().getUser();
                String email = u.getEmail();
                if (email.isEmpty()) {
                    ToastUtils.showShortToast("您还未绑定邮箱，请绑定邮箱后才可发送账单.");
                } else {
                    mOnItmeclick.onItemClickListern();
                }
                dismiss();
            }
        });

        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(w / 2 + 50);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);

    }

    public void showPopupWindow(SendEmailPopWindow pop, View parent) {
        if (!pop.isShowing()) {
            pop.showAsDropDown(parent, parent.getLayoutParams().width / 2, -DisplayUtils.dp2px(12));
            Uplayout.setVisibility(View.VISIBLE);
        } else {
            pop.dismiss();
            Uplayout.setVisibility(View.GONE);
        }
    }

    interface onItmeclick {
        public void onItemClickListern();
    }

}
